#!groovy
@Library(["pipeline-library@master"]) _

def credentials

node("maven") {
    stage("SETUP: Create secret") {
        def secret = """
                kind: Secret
                apiVersion: v1
                metadata:
                    name: cluster-credential
                type: Opaque
                stringData:
                    api: openshift.com:8443
                    token: YmxhaAo=
                """

        writeFile file: "secret-example.yml", text: secret

        openshift.withCluster() {
            openshift.withProject() {
                openshift.apply("-f", "secret-example.yml")
            }
        }

        openshift.logLevel(10)
    }

    stage("TEST: Can get credential") {
        credentials = clusterCredentials([
                secretName: "cluster-credential"
        ])
    }

    stage("ASSERT") {
        assert credentials != null
    }
}
